#include <QtGui>
#include "YoungLogon.h"
#include "ui_DlgLogon.h"
#include "Global.h"

DlgLogon::DlgLogon(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{

    setWindowFlags( Qt::FramelessWindowHint ); //| Qt::Tool
   // setAttribute(Qt::WA_TranslucentBackground, true);

    ui->setupUi(this);

    QString strFileRes;
    int iHour = GetHour();
    if( iHour >= 6 && iHour <11)
    {
        strFileRes =":/QQ/Skin/Res/Loginpanel2/morning";
    }
    else if( iHour >= 11 && iHour <13)
    {
        strFileRes =":/QQ/Skin/Res/Loginpanel2/noon";
    }
    else if( iHour >= 13 && iHour <18)
    {
        strFileRes =":/QQ/Skin/Res/Loginpanel2/afternoon";
    }
    else
    {
         strFileRes =":/QQ/Skin/Res/Loginpanel2/night";
    }

    QFile fileRes(strFileRes+".swf");
    fileRes.open(QIODevice::ReadOnly);
    QByteArray b=fileRes.readAll();
    QFile file(QApplication::applicationDirPath()+"/tmp.swf");
    file.open(QIODevice::WriteOnly);
    file.write(b);
    file.close();

    ui->lblBG->setPixmap(QPixmap(strFileRes+".jpg"));


   // ui->flash->setControl(QString::fromUtf8("{d27cdb6e-ae6d-11cf-96b8-444553540000}"));
   // ui->flash->dynamicCall("LoadMovie(long,string)",0,QApplication::applicationDirPath()+"/tmp.swf");   //
   // ui->flash->show();

    SetRoundRect();





}
void DlgLogon::SetRoundRect()
{
    QBitmap bmp(this->size());
    bmp.fill();
    QPainter p(&bmp);

    p.setRenderHint(QPainter::Antialiasing);
  //  p.drawRoundedRect(bmp.rect(), 20, 20); //四个角都是圆弧
    //只要上边角圆弧
    int arcR = 5;
    QRect rect = this->rect();
    QPainterPath path;
    //逆时针
    path.moveTo(arcR, 0);
    path.arcTo(0, 0, arcR * 2, arcR * 2, 90.0f, 90.0f);

    path.lineTo(0, rect.height() - arcR * 2);
    path.arcTo(0, rect.height() - arcR*2,  arcR * 2, arcR * 2, 180.0f, 90.0f);

    path.lineTo(rect.width(), rect.height());
    path.arcTo(rect.width() - arcR * 2, rect.height() - arcR * 2, arcR * 2, arcR * 2, 270.0f, 90.0f);

    path.lineTo(rect.width(), arcR);
    path.arcTo(rect.width() - arcR * 2, 0, arcR * 2, arcR * 2, 0.0f, 90.0f);

  //  path.lineTo(arcR, 0);


    p.drawPath(path);
    p.fillPath(path, QBrush(Qt::red));
    setMask(bmp);
}

void DlgLogon::paintEvent(QPaintEvent * e)
{

}


void DlgLogon::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) //点击左边鼠标
    {
        m_bMouseDown = true;
        QPoint ps = event->pos();
        if (this->parent()!=NULL)
        {
            QWidget* w=(QWidget*)this->parent();
            m_MoveWindowPos = event->globalPos() - w->frameGeometry().topLeft();
        }
        else
        {
            m_MoveWindowPos = event->globalPos() - frameGeometry().topLeft();
        }

        //globalPos()获取根窗口的相对路径，frameGeometry().topLeft()获取主窗口左上角的位置
        event->accept();   //鼠标事件被系统接收
    }
    event->ignore();


}
void DlgLogon ::mouseReleaseEvent(QMouseEvent *event)
{
    m_bMouseDown = false;
}
void DlgLogon::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() == Qt::LeftButton && m_bMouseDown == true) //当满足鼠标左键被点击时。
    {
        if (this->parent()!=NULL)
        {
            QWidget* w=(QWidget*)this->parent();
            w->move(event->globalPos() - m_MoveWindowPos);//移动窗口
        }
        else
        {
            move(event->globalPos() - m_MoveWindowPos);
        }

        event->accept();
    }
}

DlgLogon::~DlgLogon()
{
    delete ui;
}

void DlgLogon::on_BtnLogon_clicked()
{

}
